package walkera.cn.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.util.List;

import walkera.cn.httpserve.bean.PicBean;
import walkera.cn.httpserve.mApi.PicInfoApi;
import walkera.cn.httpserve.subscribers.HttpSubscriber;
import walkera.cn.httpserve.subscribers.PicInfoSubscriberListener;
import walkera.cn.retrofit_rxjava_okhttp.R;

public class MainActivity extends Activity {

    private final String TAG="MainActivity" ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.testGet).setOnClickListener(onClickListener);
        findViewById(R.id.testPost).setOnClickListener(onClickListener);
    }




    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.testGet:
                    testUrlGet();
                    break;
                case R.id.testPost:
                    testUrlPost( );
                    break;
                default:
                    break;
            }
        }
    };


    private String token= "" ;
    private int pageNum = 6 ;

    private void testUrlGet()
    {
        PicInfoApi.getInstance().getPicListByGet(  new HttpSubscriber<List<PicBean>>(new PicInfoSubscriberListener () {
            @Override
            public void onSucceed(List<PicBean> data) {

                if(data != null && data.size() > 0)
                {
                    Log.i(TAG , " getPicListByGet  获取数据="+ data.size()) ;
                }else{
                    Log.i(TAG , " getPicListByGet 没有获取到数据") ;
                }

            }

            @Override
            public void onError(int code, String msg) {
                Log.i(TAG , " getPicListByGet 发生异常:  code="+code +"   msg="+msg ) ;
            }
        },  this) , pageNum);
    }


    private void testUrlPost( )
    {
        PicInfoApi.getInstance().getPicListByPost(  new HttpSubscriber<List<PicBean>>(new PicInfoSubscriberListener () {
            @Override
            public void onSucceed(List<PicBean> data) {

                if(data != null && data.size() > 0)
                {
                    Log.i(TAG , " testUrlPost 获取数据="+ data.size()) ;
                }else{
                    Log.i(TAG , " testUrlPost 没有获取到数据") ;
                }

            }

            @Override
            public void onError(int code, String msg) {
                Log.i(TAG , "testUrlPost 发生异常:  code="+code +"   msg="+msg ) ;
            }
        },  this) , pageNum);
    }



}
